//
//  Shader.h
//  Renderbunny
//
//  Created by Holmes Futrell on 1/22/11.
//  Copyright 2011 Holmes Futrell. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <OpenGLES/ES2/gl.h>

@interface ShaderProgram : NSObject {
	GLuint program;
	GLuint fragmentShader, vertexShader;
	BOOL isLinked;
}

/*
	Usage pattern
	1. init
	2. bind attributes (optional)
	3. link
	4. use
 */

// immediatly compiles vertex and fragment programs, does not link.
// returns nil of compilation fails
-(id)initWithVertexShader:(NSString *)pathVertex fragmentShader:(NSString *)pathPixel;

// shader specified location for uniform
-(int)locationForUniform:(NSString *)uniformName;

// must be done before compilation
// any unbound active attributes will automatical be bound to locations by the GL
-(void)bindAttribute:(NSString *)attribute toLocation:(GLuint)location;

// gets the location for an attribute
-(int)getLocationForAttribute:(NSString *)attribute;

// Must call before calling use.  Must bind all attributes before linking.
-(BOOL)linkProgram;
-(void)useProgram;

#pragma mark -

// get the error log(s)
-(NSString *)programInformationLog;
-(NSString *)fragmentShaderInformationLog;
-(NSString *)vertexShaderInformationLog;

// validates program against current GL state (will the program run?)
// overwrites information log if FALSE
-(BOOL)validateProgram;

#pragma mark -

@property (readonly) BOOL isLinked;
@property (readonly) GLuint program;

@end
